﻿using MediatR;
using Traceability.APP.Application.Command.Butcher;
using Traceability.Domain;
using Traceability.ErrorCode;
using Traceability.Infrerture.Interfaces;

namespace Traceability.APP.Application.CommandHandle.Butcher
{
    /// <summary>
    /// 屠宰信息的显示
    /// </summary>
    public class ShowButcherCommandHandle:IRequestHandler<ShowButcherCommand,APIResult<List<Butcher_Model>>>
    {
        private readonly IBaseRepository<Butcher_Model> ButcherDal;

        public ShowButcherCommandHandle(IBaseRepository<Butcher_Model> butcherDal)
        {
            ButcherDal = butcherDal;
        }

        public Task<APIResult<List<Butcher_Model>>> Handle(ShowButcherCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Butcher_Model>> result = new APIResult<List<Butcher_Model>>();
            var list = ButcherDal.GetAll().Where(x => x.Batch == request.Batch && x.IsDeleted == false);
            result.Code = StateCode.Ok;
            result.Message = StateCode.Ok.ToString();
            result.Data = list.ToList();
            return Task.FromResult(result);
        }



    }
}
